package chain

import "fmt"

type IHandelLog interface {
	Handel(myLogger *MyLogger)
}

type MyLogger struct {
	Level int
}

type ConsoleHandelLog struct {
	nextHandel IHandelLog
}

func (c *ConsoleHandelLog) SetNext(handel IHandelLog) {
	c.nextHandel = handel
}

func (c *ConsoleHandelLog) Handel(myLogger *MyLogger) {
	if myLogger.Level <= 1 {
		fmt.Println("console -- log")
	}
	if c.nextHandel != nil {
		c.nextHandel.Handel(myLogger)
	}
}

type FileHandelLog struct {
	nextHandel IHandelLog
}

func (c *FileHandelLog) SetNext(handel IHandelLog) {
	c.nextHandel = handel
}

func (c *FileHandelLog) Handel(myLogger *MyLogger) {
	if myLogger.Level <= 2 {
		fmt.Println("文件 -- log")
	}
	if c.nextHandel != nil {
		c.nextHandel.Handel(myLogger)
	}
}
